#include "bsp_dac8532.h"


#define DACS_HIGH   LPC_GPIO0->FIOSET |= (1<<7)
#define DACS_LOW    LPC_GPIO0->FIOCLR |= (1<<7)
#define SCK_HIGH  LPC_GPIO0->FIOSET |= (1<<15)
#define SCK_LOW	  LPC_GPIO0->FIOCLR |= (1<<15)
#define DOUT_HIGH LPC_GPIO0->FIOSET |= (1<<18)
#define DOUT_LOW  LPC_GPIO0->FIOCLR |= (1<<18)
void WriteDac8532(uint8_t command,uint16_t value)
{
	uint8_t i,cmd=0x80;
	uint16_t val=0x8000;
//	DACS_HIGH;
//	SCK_LOW;
//	DACS_LOW;
	
	for(i=0;i<8;i++)	//先发送命令码
	{
		SCK_HIGH;	
		if(command & cmd)
			DOUT_HIGH;
		else
			DOUT_LOW;
		SCK_LOW;		//构造下降沿传输数据
		cmd >>= 1;
	}
	for(i=0;i<16;i++)		//发送数据
	{
		SCK_HIGH;
		if(value & val)
			DOUT_HIGH;
		else
			DOUT_LOW;
		SCK_LOW;
		val >>= 1;
	}
	DACS_HIGH;
	SCK_HIGH;
	
}
